/*******************************************************************************
 * 版权：北京润尼尔网络科技有限公司，保留所有版权<br>
 * 版本：v1.0.0<br>
 * 文件：DeviceModelEventHandlerSetDevName.js<br>
 * 日期：2018年8月1日<br>
 * 作者: 李姣<br>
 * 功能：自定义模型事件处理器<br>
 * 
 * 修改记录：<br>
 * 日期 描述 更新功能<br>
 ******************************************************************************/

window.makeNamespace(window,"Rainier.UI.V2");

/**
 * 类型名称：Rainier.UI.V2.DeviceModelEventHandlerSetDevName<br>
 * 类型功能：模型事件请求<br>
 */
Rainier.UI.V2.DeviceModelEventHandlerSetDevName = Rainier.UI.V2.ModelEventHandler.extend({
	
	NAME : "Rainier.UI.V2.DeviceModelEventHandlerSetDevName",
	
	/**
	 * 函数名称：Rainier.UI.V2.DeviceModelEventHandlerSetDevName.init<br>
	 * 函数功能：构造函数<br>
	 * 异常信息：无<br>
	 */
	init : function(){
		this._super();
		this.editPart = null;
		this.oldDevName = null;
		this.newDevName = null;
	},
	
	/**
	 * 函数名称：Rainier.UI.V2.DeviceModelEventHandlerSetDevName.setEditPart<br>
	 * 函数功能：设置EditPart<br>
	 * 参数输入：editPart:DeviceEditPart<br>
	 * 函数返回：无<br>
	 * 异常信息：无<br>
	 */
	setEditPart : function(editPart){
		this.editPart = editPart;
	},
	
	/**
	 * 函数名称：Rainier.UI.V2.DeviceModelEventHandlerSetDevName.setOldDevName<br>
	 * 函数功能：设置老的名称<br>
	 * 参数输入：devName:String<br>
	 * 函数返回：无<br>
	 * 异常信息：无<br>
	 */
	setOldDevName : function(devName){
		this.oldDevName = devName;
	},
	
	/**
	 * 函数名称：Rainier.UI.V2.DeviceModelEventHandlerSetDevName.setNewDevName<br>
	 * 函数功能：设置新的标签<br>
	 * 参数输入：devName:String<br>
	 * 函数返回：无<br>
	 * 异常信息：无<br>
	 */
	setNewDevName : function(devName){
		this.newDevName = devName;
	},
	
    /**
	 * 函数名称：draw2d.command.Command.canExecute<br>
	 * 函数功能：是否能够执行命令<br>
	 * 函数返回：Boolean<br>
	 * 异常信息：无<br>
	 */
    canExecute:function(){
		if(this.editPart && this.oldDevName && this.newDevName){
			return true;
		}
    	return false;
    },
    
    /**
	 * 函数名称：draw2d.command.Command.execute<br>
	 * 函数功能：执行命令<br>
	 * 函数返回：无<br>
	 * 异常信息：无<br>
	 */
    execute:function(){
       var figure 	= this.editPart.getFigure();
       var model  	= this.editPart.getModel();
       var property = model.property;
       if(!property){debugger;return;}
       if(!property.modelProperty){debugger;return;}
    //    if(!property.modelProperty.label){debugger;return;}
       var typeName = model.property.modelProperty.typeName.substring(0,9);
       if(typeName == 'TextModel'){
       	return;
       }else{
       	model.setDevName(this.newDevName);
       	figure.devNameFigure.setText(this.newDevName);
	}
    },
    
    /**
	 * 函数名称：draw2d.command.Command.undo<br>
	 * 函数功能：撤销命令<br>
	 * 函数返回：无<br>
	 * 异常信息：无<br>
	 */
    undo:function(){
        var figure 	= this.editPart.getFigure();
        var model  	= this.editPart.getModel();
        var property = model.property;
        if(!property){debugger;return;}
        if(!property.modelProperty){debugger;return;}
        if(!property.modelProperty.label){debugger;return;}
        
        model.setDevName(this.oldDevName,true,false,this.editPart);
        figure.deviceNameFigure.setText(this.oldDevName);
    },
    
    /**
	 * 函数名称：draw2d.command.Command.redo<br>
	 * 函数功能：重做命令<br>
	 * 函数返回：无<br>
	 * 异常信息：无<br>
	 */
    redo:function(){
        var figure 	= this.editPart.getFigure();
        var model  	= this.editPart.getModel();
        var property = model.property;
        if(!property){debugger;return;}
        if(!property.modelProperty){debugger;return;}
        if(!property.modelProperty.label){debugger;return;}
        
        model.setDevName(this.newDevName,true,false,this.editPart);
        figure.deviceNameFigure.setText(this.newDevName);
    }

});
